package com.demo.test.controller;

import com.demo.test.entity.Sing;
import com.demo.test.entity.Toupiao;
import com.demo.test.service.IToupiaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XieHuan
 * @since 2017-06-10
 */
@Controller
@RequestMapping("/toupiao")
public class ToupiaoController {

    @Autowired
    private IToupiaoService iToupiaoService;

    @RequestMapping("/index.html")
    public String shouye(){
        return "_toupiao/index";
    }
    @RequestMapping("/shouye.html")
    public String shouye1(){
        return "_toupiao/shouye";
    }
    @RequestMapping("/pk.html")
    public String pk(){
        return "_toupiao/pk";
    }

    @RequestMapping("/pkinfo.html")
    public  String pkinfo(){
        return "_toupiao/pkinfo";
    }

    @RequestMapping("/toupiaoInsert")
    @ResponseBody
    public int toupiao(@RequestBody Sing sing,HttpSession session){
        String userSession = session.getId();

        System.out.println(userSession);
        Toupiao tp=new Toupiao();
        tp.setYonghuid(userSession);

        List<Toupiao> toupiaoList=iToupiaoService.selectByUserId(userSession);

        if(toupiaoList.size()==0){
            Toupiao toupiao=new Toupiao();
            toupiao.setSingid(sing.getId()+"");
            toupiao.setYonghuid(userSession);
            toupiao.setQiao(1+"");
            boolean f= iToupiaoService.insert(toupiao);
            if (f==true){
                return 1;
            }else{
                return 0;
            }
        }else{
            return 2;
        }

    }
	
}
